package factory.one.command;

import factory.one.entity.SysColumn;
import factory.one.entity.SysTable;
import factory.one.service.DatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sk.z
 * 2023/7/4
 * 数据库
 **/
@Service
public class CmdDatabase {

    @Autowired
    private DatabaseService databaseService;

    public void create(String sql) {
        databaseService.execute(sql);
    }

    public void desc(String tableId) {
        List<SysColumn> sysColumns = databaseService.descTable(tableId);
        for (SysColumn column : sysColumns) {
            System.out.println(column.getName() + " " + column.getDataType());
        }
    }

    public void show(String param) {
        if (param.contains("table")) {
            List<SysTable> userTables = databaseService.getUserTables();
            for (SysTable t : userTables) {
                System.out.println(t.getName() + " " + t.getId());
            }
        }
    }

    public void path1(){
        //databaseService.execute("alter table \"BATCH\" add column STATUS int default 1");
    }

}
